<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

include_once $_SERVER['DOCUMENT_ROOT'] . '/class/Product_order.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/class/Material.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/class/Db.php';
$statement=$_POST['statement'];//传订单状态
$pro_number=$_POST['pro_number'];//成品数量
$materials=$_POST['materials'];//二维数组，传 material_id 和 number 过来


     if($statement=='进行中'){//开始订单，原料库扣除原料
        foreach ($materials as $material_item) {
          $number = $material_item['number'];
          $sql.="UPDATE fac_material_mess SET number=number-$number";
             $material_id = $material_item['material_id'];
            $sql.=" WHERE material_id=$material_id ;" ;

        }
        echo $sql;

        $sql = substr($sql, 0, strlen($sql) - 1);
      
        return Db::get_instance()->query($sql) > 0;
    } 
    elseif($statement=='已完成'){//完成订单，添加到成品库存
       
       $sql="UPDATE fac_product_mess SET number=number+$pro_number WHERE  product_id=$product_id";
       return Db::get_instance()->query($sql);
                   
   }else{
       echo 0;              
   }
    
     


     
      